`include "common.svh"
module mcore (
    input           clk,
    input           rst,
    // IRAM Req
    input           o_iram_ready,
    output          o_iram_valid,
    output IRAM_Req o_iram_req,
    // IRAM Rsp
    input  IRAM_Rsp i_iram_rsp,
    //Memory Req Port
    output          o_mem_req_valid,
    output MEM_REQ  o_mem_req,
    input           o_mem_req_ready,
    output          o_mem_req_kill_prev,
    input           i_mem_early_wakeup_valid,
    input  PRF_IDX  i_mem_early_wakeup_prf_idx,
    //Memory Rsp Port
    input           i_mem_rsp_valid,
    input  MEM_RSP  i_mem_rsp,
    output          i_mem_rsp_ready
);
  localparam FRONTEND_WIDTH = 2;
  logic frontend_i_redirect_valid;
  logic frontend_i_redirect_replay;
  word_t frontend_i_redirect_pc;
  logic frontend_i_redirect_bpu_res_valid;
  BPU_Res frontend_i_redirect_bpu_res;
  logic frontend_o_ibuf_valid;
  logic frontend_o_ibuf_ready;
  logic frontend_o_ibuf_entry_valid[FRONTEND_WIDTH-1:0];
  IBUF_Entry frontend_o_ibuf_entry[FRONTEND_WIDTH-1:0];
  /* verilator lint_off UNUSEDSIGNAL */
  logic frontend_ibuf_full;
  logic frontend_ibuf_empty;
  /* verilator lint_on UNUSEDSIGNAL */
  frontend #(FRONTEND_WIDTH) inst_frontend (
      .i_redirect_valid(frontend_i_redirect_valid),
      .i_redirect_replay(frontend_i_redirect_replay),
      .i_redirect_pc(frontend_i_redirect_pc),
      .i_redirect_bpu_res_valid(frontend_i_redirect_bpu_res_valid),
      .i_redirect_bpu_res(frontend_i_redirect_bpu_res),
      .o_ibuf_valid(frontend_o_ibuf_valid),
      .o_ibuf_ready(frontend_o_ibuf_ready),
      .o_ibuf_entry_valid(frontend_o_ibuf_entry_valid),
      .o_ibuf_entry(frontend_o_ibuf_entry),
      .ibuf_full(frontend_ibuf_full),
      .ibuf_empty(frontend_ibuf_empty),
      .*
  );
  `PERF_EVENT(ibuf_full, frontend_ibuf_full);
  `PERF_EVENT(frontend_bubble, frontend_ibuf_empty);
  `PERF_EVENT(frontend_stall_by_backend,
              frontend_o_ibuf_valid & frontend_o_ibuf_entry_valid[0] & ~frontend_o_ibuf_ready);
  `PERF_EVENT(backend_stall, frontend_o_ibuf_ready);
  localparam COMMIT_WIDTH = 2;
  backend #(FRONTEND_WIDTH, COMMIT_WIDTH) inst_backend (
      .i_ibuf_valid(frontend_o_ibuf_valid),
      .i_ibuf_ready(frontend_o_ibuf_ready),
      .i_ibuf_entry_valid(frontend_o_ibuf_entry_valid),
      .i_ibuf_entry(frontend_o_ibuf_entry),
      .o_redirect_valid(frontend_i_redirect_valid),
      .o_redirect_replay(frontend_i_redirect_replay),
      .o_redirect_pc(frontend_i_redirect_pc),
      .o_redirect_bpu_res_valid(frontend_i_redirect_bpu_res_valid),
      .o_redirect_bpu_res(frontend_i_redirect_bpu_res),
      .*
  );
  difftest #(COMMIT_WIDTH) inst_difftest (.*);

endmodule

